-------------------------------------------------------------------------------
--  The Legend of Zelda : Oracle of Secrets
--  Copyright (C) 2010 Pixelua
--
--  This program is free software: you can redistribute it and/or modify
--  it under the terms of the GNU General Public License as published by
--  the Free Software Foundation, either version 3 of the License, or
--  (at your option) any later version.
--
--  This program is distributed in the hope that it will be useful,
--  but WITHOUT ANY WARRANTY; without even the implied warranty of
--  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
--  GNU General Public License for more details.
--
--  You should have received a copy of the GNU General Public License
--  along with this program.  If not, see <http://www.gnu.org/licenses/>.
-------------------------------------------------------------------------------
color_tab = {
	"blue",blue,
	"white",white,
	"black",black,
	"orange",orange
}

function bbcode_print(scr,x,y,str,main_color)
   local pos = 1
	
	while true do
		start,stop,balise,valeur,text = str:find("%[(%a+)=(%a+)%](.-)%[/%1%]",pos)
		if not start then break end
		
		if start > pos then
			local normalContent = str:sub(pos, start-1)
			screen_print(scr, x, y, normalContent, main_color)
			x = x+(#normalContent*8)
		end
		
		-- Affichage
		if balise == "color" then
			for color_i=1, #color_tab,2 do
				if color_tab[color_i] == valeur then
					screen_print(scr, x, y, text, color_tab[color_i+1])
					break
				end
			end
		end
		
		x = x+(#text*8)
		pos = stop + 1   
	end
	
	text = str:sub(pos)
   screen_print(scr, x, y, text, main_color)
end